package model;

/**
 * @author  megea
 */
public class Cistern extends Source{

    private Double totalCapacity;
    /**
     * @uml.property  name="amountContentFull"
     */
    private Double amountContentFull;

    public Cistern(Double totalCapacity, Integer id) {
        super(new SensedValue(Double.valueOf(0)), id);
        this.totalCapacity = totalCapacity;
        this.setAmountContentFull(getMinValue());
    }

    /**
     * @return
     * @uml.property  name="amountContentFull"
     */
    public Double getAmountContentFull() {
        return amountContentFull;
    }

    /**
     * @param amountContentFull
     * @uml.property  name="amountContentFull"
     */
    private void setAmountContentFull(Double amountLiquidFull) {
        this.amountContentFull = amountLiquidFull;
    }

    public Double empty(){
        Double content = amountContentFull;
        amountContentFull = getMinValue();
        return content;
    }

    public Double emptyStep(Double step){
        Double liquidEmpty;
        if ((amountContentFull - step) < 0){
            liquidEmpty = amountContentFull;
            amountContentFull = getMinValue();
        }else{
            amountContentFull = amountContentFull - step;
            liquidEmpty = step;
        }

        return liquidEmpty;
    }

    public Double getFullPercentage(){
        return (totalCapacity/amountContentFull) * 100;
    }

    public Double addContent(Double content){
        if ((amountContentFull + content) <= totalCapacity.doubleValue()){
            amountContentFull += content;
            return Double.valueOf(0);
        }else{
            Double waste = (amountContentFull + content) - totalCapacity;
            amountContentFull = totalCapacity;
            return waste;
        }
    }

    @Override
    public SensedValue getValue() {
        return new SensedValue(amountContentFull);
    }

    public Double getRest() {
        return totalCapacity - amountContentFull;
    }

    @Override
    public Double getMaxValue() {
        return totalCapacity;
    }

    @Override
    public Double getMinValue() {
        return Double.valueOf(0);
    }
}
